# ============================================================
# Thomas König & Stefan Eschenwecker
# The European Court of Justice and legal European integration
# 
# This script produces Figures A1 + A2 in the online appendix.
# ============================================================

# load packages
library(tidyverse)
library(patchwork)

# set plot options
theme_set(theme_bw(base_size = 14))

# load data
CourtData <- read.csv("Court/Data/PreparedCourtData.csv") %>% 
  filter(all_not_applic == 0)

# plot of signal direction (Figure A1)
DirectionPlot <- ggplot(CourtData) +
  geom_density(aes(net_ms_pref),
               color = "black", fill = "grey") +
  xlab("Weighted Net Preferences") +
  ylab("Density")

ggsave(plot = DirectionPlot, device = "pdf",
       filename = "MSSignalDirection.pdf",
       path = "Court/Plots/", height = 6, width = 8)


# plot of signal strength (Figure A2)
StrengthPlot <- ggplot(CourtData) +
  geom_histogram(aes(ms_signal_int,
                     y = after_stat(count / sum(count, na.rm = T))),
                 color = "black", fill = "grey",
                 bins = 14, binwidth = 0.5) +
  scale_y_continuous(labels = scales::percent_format()) +
  scale_x_continuous(breaks = c(0:13)) +
  xlab("Number of Amicus Curiae Briefs") +
  ylab("Share") 

ggsave(plot = StrengthPlot, device = "pdf",
       filename = "MSSignalStrength.pdf",
       path = "Court/Plots/", height = 6, width = 8)
